package cn.study.luckydomain.activity;

import cm.study.config.exception.LdException;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.Objects;

@Data
public class ActivityTime {
    private LocalDateTime startTime;
    private LocalDateTime endTime;
    public ActivityTime(LocalDateTime startTime,LocalDateTime endTime){
        if(Objects.isNull(startTime)||Objects.isNull(endTime)){
            throw new LdException("活动时间不能为空");
        }
        if(startTime.isAfter(endTime)){
            throw new LdException("活动时间非法");
        }
        this.startTime=startTime;
        this.endTime=endTime;
    }
    public ActivityStatusEnum getStatus(){
        LocalDateTime now=LocalDateTime.now();
        if(now.isBefore(startTime)){
            return ActivityStatusEnum.NOT_START;
        }
        else if(now.isAfter(startTime)&&now.isBefore(endTime)){
            return ActivityStatusEnum.START;
        }
        return ActivityStatusEnum.END;
    }
}
